package com.supermap.rootstock.admin.aritmetic;

import com.supermap.rootstock.admin.api.admin.arithmetic.ArithmeticParam;
import com.supermap.rootstock.admin.api.entity.Arithmetic;
import com.supermap.rootstock.admin.api.util.JSONUtil;
import com.supermap.rootstock.admin.mapper.AritmeticMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


/**
 * @author aqua
 * @description
 * @date 2019年09月12 15:40
 * @email 1301584033@qq.com
 */
@Slf4j
@Service
@AllArgsConstructor
public class AritmeticServiceImpl implements AritmeticService {

	private final AritmeticMapper aritmeticMapper;


	@Override
	public JSONUtil getPageArithmeticList(String name, Integer systemId, Integer langId, Integer pageNum, Integer pageSize) {

		return new JSONUtil().setData(aritmeticMapper
			.getPageArithmeticList(name,systemId,langId,pageNum,pageSize))
			.setCountSum(aritmeticMapper.getPageArithmeticListCountNum(name,systemId,langId));
	}

	@Override
	public JSONUtil getArithmeticById(Integer aId) {
		return new JSONUtil().setData(aritmeticMapper.getArithmeticById(aId));
	}

	@Override
	public JSONUtil getArithmeticLangList() {
		return new JSONUtil().setData(aritmeticMapper.getArithmeticLangList());
	}

	@Override
	public JSONUtil getArithmeticSystemList() {
		return new JSONUtil().setData(aritmeticMapper.getArithmeticSystemList());
	}

	@Override
	public JSONUtil putArithmetic(Arithmetic arithmetic) {
		aritmeticMapper.putArithmetic(arithmetic);
		Integer ID=aritmeticMapper.getId();
		aritmeticMapper.delArithmeticParms(ID);
	 	 List<ArithmeticParam> alist=arithmetic.getAlist();
		alist.stream().forEach(arithmeticParam -> {
			arithmeticParam.setAritId(ID);
		});
		aritmeticMapper.putArithmeticParms(alist);
		return new JSONUtil();
	}

	@Override
	public JSONUtil postAudit(Integer state, Integer suserId, String scontent) {
		return new JSONUtil().setData(aritmeticMapper.postAudit(state,suserId,scontent));
	}
}
